package org.freez4.spring.configuration.metadata;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 基于 XML 资源的 YAML 外部化配置示例
 *
 * @author 阿坤同学
 * @date 2024/1/15 4:38 PM
 */
public class XmlBasedYamlPropertySourceDemo {
    private static final Logger logger = Logger.getLogger(XmlBasedYamlPropertySourceDemo.class.getName());

    public static void main(String[] args) {
        // 创建 IoC 底层容器
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        // 创建 XML 资源的 BeanDefinitionReader
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        // 记载 XML 资源
        reader.loadBeanDefinitions("classpath:/META-INF/yaml-property-source-context.xml");
        // 获取 Map YAML 对象
        Map<String, Object> yamlMap = beanFactory.getBean("yamlMap", Map.class);
        logger.log(Level.INFO, () -> "yamlMap:" + yamlMap);
    }
}